woodburn.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /*
  2. * Copyright (C) 2012, Stefano Babic <sbabic@denx.de>
  3. *
  4. * Based on flea3.c and mx35pdk.c
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/errno.h>
  27. #include <asm/arch/imx-regs.h>
  28. #include <asm/arch/crm_regs.h>
  29. #include <asm/arch/clock.h>
  30. #include <asm/arch/mx35_pins.h>
  31. #include <asm/arch/iomux.h>
  32. #include <i2c.h>
  33. #include <power/pmic.h>
  34. #include <fsl_pmic.h>
  35. #include <mc13892.h>
  36. #include <mmc.h>
  37. #include <fsl_esdhc.h>
  38. #include <linux/types.h>
  39. #include <asm/gpio.h>
  40. #include <asm/arch/sys_proto.h>
  41. #include <netdev.h>
  42. #include <spl.h>
  43. #define CCM_CCMR_CONFIG 0x003F4208
  44. #define ESDCTL_DDR2_CONFIG 0x007FFC3F
  45. /* For MMC */
  46. #define GPIO_MMC_CD 7
  47. #define GPIO_MMC_WP 8
  48. DECLARE_GLOBAL_DATA_PTR;
  49. int dram_init(void)
  50. {
  51. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
  52. PHYS_SDRAM_1_SIZE);
  53. return 0;
  54. }
  55. static void board_setup_sdram(void)
  56. {
  57. struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
  58. /* Initialize with default values both CSD0/1 */
  59. writel(0x2000, &esdc->esdctl0);
  60. writel(0x2000, &esdc->esdctl1);
  61. mx3_setup_sdram_bank(CSD0_BASE_ADDR, ESDCTL_DDR2_CONFIG,
  62. 13, 10, 2, 0x8080);
  63. }
  64. static void setup_iomux_fec(void)
  65. {
  66. /* setup pins for FEC */
  67. mxc_request_iomux(MX35_PIN_FEC_TX_CLK, MUX_CONFIG_FUNC);
  68. mxc_request_iomux(MX35_PIN_FEC_RX_CLK, MUX_CONFIG_FUNC);
  69. mxc_request_iomux(MX35_PIN_FEC_RX_DV, MUX_CONFIG_FUNC);
  70. mxc_request_iomux(MX35_PIN_FEC_COL, MUX_CONFIG_FUNC);
  71. mxc_request_iomux(MX35_PIN_FEC_RDATA0, MUX_CONFIG_FUNC);
  72. mxc_request_iomux(MX35_PIN_FEC_TDATA0, MUX_CONFIG_FUNC);
  73. mxc_request_iomux(MX35_PIN_FEC_TX_EN, MUX_CONFIG_FUNC);
  74. mxc_request_iomux(MX35_PIN_FEC_MDC, MUX_CONFIG_FUNC);
  75. mxc_request_iomux(MX35_PIN_FEC_MDIO, MUX_CONFIG_FUNC);
  76. mxc_request_iomux(MX35_PIN_FEC_TX_ERR, MUX_CONFIG_FUNC);
  77. mxc_request_iomux(MX35_PIN_FEC_RX_ERR, MUX_CONFIG_FUNC);
  78. mxc_request_iomux(MX35_PIN_FEC_CRS, MUX_CONFIG_FUNC);
  79. mxc_request_iomux(MX35_PIN_FEC_RDATA1, MUX_CONFIG_FUNC);
  80. mxc_request_iomux(MX35_PIN_FEC_TDATA1, MUX_CONFIG_FUNC);
  81. mxc_request_iomux(MX35_PIN_FEC_RDATA2, MUX_CONFIG_FUNC);
  82. mxc_request_iomux(MX35_PIN_FEC_TDATA2, MUX_CONFIG_FUNC);
  83. mxc_request_iomux(MX35_PIN_FEC_RDATA3, MUX_CONFIG_FUNC);
  84. mxc_request_iomux(MX35_PIN_FEC_TDATA3, MUX_CONFIG_FUNC);
  85. }
  86. int woodburn_init(void)
  87. {
  88. struct ccm_regs *ccm =
  89. (struct ccm_regs *)IMX_CCM_BASE;
  90. /* initialize PLL and clock configuration */
  91. writel(CCM_CCMR_CONFIG, &ccm->ccmr);
  92. /* Set-up RAM */
  93. board_setup_sdram();
  94. /* enable clocks */
  95. writel(readl(&ccm->cgr0) |
  96. MXC_CCM_CGR0_EMI_MASK |
  97. MXC_CCM_CGR0_EDIO_MASK |
  98. MXC_CCM_CGR0_EPIT1_MASK,
  99. &ccm->cgr0);
  100. writel(readl(&ccm->cgr1) |
  101. MXC_CCM_CGR1_FEC_MASK |
  102. MXC_CCM_CGR1_GPIO1_MASK |
  103. MXC_CCM_CGR1_GPIO2_MASK |
  104. MXC_CCM_CGR1_GPIO3_MASK |
  105. MXC_CCM_CGR1_I2C1_MASK |
  106. MXC_CCM_CGR1_I2C2_MASK |
  107. MXC_CCM_CGR1_I2C3_MASK,
  108. &ccm->cgr1);
  109. /* Set-up NAND */
  110. __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
  111. /* Set pinmux for the required peripherals */
  112. setup_iomux_fec();
  113. /* setup GPIO1_4 FEC_ENABLE signal */
  114. mxc_request_iomux(MX35_PIN_SCKR, MUX_CONFIG_ALT5);
  115. gpio_direction_output(4, 1);
  116. mxc_request_iomux(MX35_PIN_HCKT, MUX_CONFIG_ALT5);
  117. gpio_direction_output(9, 1);
  118. return 0;
  119. }
  120. #if defined(CONFIG_SPL_BUILD)
  121. void board_init_f(ulong dummy)
  122. {
  123. /* Set the stack pointer. */
  124. asm volatile("mov sp, %0\n" : : "r"(CONFIG_SPL_STACK));
  125. /* Initialize MUX and SDRAM */
  126. woodburn_init();
  127. /* Clear the BSS. */
  128. memset(__bss_start, 0, __bss_end__ - __bss_start);
  129. /* Set global data pointer. */
  130. gd = &gdata;
  131. preloader_console_init();
  132. timer_init();
  133. board_init_r(NULL, 0);
  134. }
  135. void spl_board_init(void)
  136. {
  137. }
  138. #endif
  139. /* Booting from NOR in external mode */
  140. int board_early_init_f(void)
  141. {
  142. return woodburn_init();
  143. }
  144. int board_init(void)
  145. {
  146. struct pmic *p;
  147. u32 val;
  148. int ret;
  149. /* address of boot parameters */
  150. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  151. ret = pmic_init(I2C_PMIC);
  152. if (ret)
  153. return ret;
  154. p = pmic_get("FSL_PMIC");
  155. /*
  156. * Set switchers in Auto in NORMAL mode & STANDBY mode
  157. * Setup the switcher mode for SW1 & SW2
  158. */
  159. pmic_reg_read(p, REG_SW_4, &val);
  160. val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
  161. (SWMODE_MASK << SWMODE2_SHIFT)));
  162. val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
  163. (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
  164. /* Set SWILIMB */
  165. val |= (1 << 22);
  166. pmic_reg_write(p, REG_SW_4, val);
  167. /* Setup the switcher mode for SW3 & SW4 */
  168. pmic_reg_read(p, REG_SW_5, &val);
  169. val &= ~((SWMODE_MASK << SWMODE4_SHIFT) |
  170. (SWMODE_MASK << SWMODE3_SHIFT));
  171. val |= (SWMODE_AUTO_AUTO << SWMODE4_SHIFT) |
  172. (SWMODE_AUTO_AUTO << SWMODE3_SHIFT);
  173. pmic_reg_write(p, REG_SW_5, val);
  174. /* Set VGEN1 to 3.15V */
  175. pmic_reg_read(p, REG_SETTING_0, &val);
  176. val &= ~(VGEN1_MASK);
  177. val |= VGEN1_3_15;
  178. pmic_reg_write(p, REG_SETTING_0, val);
  179. pmic_reg_read(p, REG_MODE_0, &val);
  180. val |= VGEN1EN;
  181. pmic_reg_write(p, REG_MODE_0, val);
  182. udelay(2000);
  183. return 0;
  184. }
  185. #if defined(CONFIG_FSL_ESDHC)
  186. struct fsl_esdhc_cfg esdhc_cfg = {MMC_SDHC1_BASE_ADDR};
  187. int board_mmc_init(bd_t *bis)
  188. {
  189. /* configure pins for SDHC1 only */
  190. mxc_request_iomux(MX35_PIN_SD1_CMD, MUX_CONFIG_FUNC);
  191. mxc_request_iomux(MX35_PIN_SD1_CLK, MUX_CONFIG_FUNC);
  192. mxc_request_iomux(MX35_PIN_SD1_DATA0, MUX_CONFIG_FUNC);
  193. mxc_request_iomux(MX35_PIN_SD1_DATA1, MUX_CONFIG_FUNC);
  194. mxc_request_iomux(MX35_PIN_SD1_DATA2, MUX_CONFIG_FUNC);
  195. mxc_request_iomux(MX35_PIN_SD1_DATA3, MUX_CONFIG_FUNC);
  196. /* MMC Card Detect on GPIO1_7 */
  197. mxc_request_iomux(MX35_PIN_SCKT, MUX_CONFIG_ALT5);
  198. mxc_iomux_set_input(MUX_IN_GPIO1_IN_7, 0x1);
  199. gpio_direction_input(GPIO_MMC_CD);
  200. mxc_request_iomux(MX35_PIN_FST, MUX_CONFIG_ALT5);
  201. mxc_iomux_set_input(MUX_IN_GPIO1_IN_8, 0x1);
  202. gpio_direction_output(GPIO_MMC_WP, 0);
  203. esdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
  204. return fsl_esdhc_initialize(bis, &esdhc_cfg);
  205. }
  206. int board_mmc_getcd(struct mmc *mmc)
  207. {
  208. return !gpio_get_value(GPIO_MMC_CD);
  209. }
  210. #endif
  211. u32 get_board_rev(void)
  212. {
  213. int rev = 0;
  214. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  215. }