woodburn.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 <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, 0);
  118. gpio_set_value(9, 1);
  119. return 0;
  120. }
  121. #if defined(CONFIG_SPL_BUILD)
  122. void board_init_f(ulong dummy)
  123. {
  124. /* Set the stack pointer. */
  125. asm volatile("mov sp, %0\n" : : "r"(CONFIG_SPL_STACK));
  126. /* Initialize MUX and SDRAM */
  127. woodburn_init();
  128. /* Clear the BSS. */
  129. memset(__bss_start, 0, __bss_end__ - __bss_start);
  130. /* Set global data pointer. */
  131. gd = &gdata;
  132. preloader_console_init();
  133. timer_init();
  134. board_init_r(NULL, 0);
  135. }
  136. void spl_board_init(void)
  137. {
  138. }
  139. #endif
  140. /* Booting from NOR in external mode */
  141. int board_early_init_f(void)
  142. {
  143. return woodburn_init();
  144. }
  145. int board_init(void)
  146. {
  147. struct pmic *p;
  148. u32 val;
  149. /* address of boot parameters */
  150. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  151. pmic_init();
  152. p = get_pmic();
  153. /*
  154. * Set switchers in Auto in NORMAL mode & STANDBY mode
  155. * Setup the switcher mode for SW1 & SW2
  156. */
  157. pmic_reg_read(p, REG_SW_4, &val);
  158. val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
  159. (SWMODE_MASK << SWMODE2_SHIFT)));
  160. val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
  161. (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
  162. /* Set SWILIMB */
  163. val |= (1 << 22);
  164. pmic_reg_write(p, REG_SW_4, val);
  165. /* Setup the switcher mode for SW3 & SW4 */
  166. pmic_reg_read(p, REG_SW_5, &val);
  167. val &= ~((SWMODE_MASK << SWMODE4_SHIFT) |
  168. (SWMODE_MASK << SWMODE3_SHIFT));
  169. val |= (SWMODE_AUTO_AUTO << SWMODE4_SHIFT) |
  170. (SWMODE_AUTO_AUTO << SWMODE3_SHIFT);
  171. pmic_reg_write(p, REG_SW_5, val);
  172. /* Set VGEN1 to 3.15V */
  173. pmic_reg_read(p, REG_SETTING_0, &val);
  174. val &= ~(VGEN1_MASK);
  175. val |= VGEN1_3_15;
  176. pmic_reg_write(p, REG_SETTING_0, val);
  177. pmic_reg_read(p, REG_MODE_0, &val);
  178. val |= VGEN1EN;
  179. pmic_reg_write(p, REG_MODE_0, val);
  180. udelay(2000);
  181. return 0;
  182. }
  183. #if defined(CONFIG_FSL_ESDHC)
  184. struct fsl_esdhc_cfg esdhc_cfg = {MMC_SDHC1_BASE_ADDR};
  185. int board_mmc_init(bd_t *bis)
  186. {
  187. /* configure pins for SDHC1 only */
  188. mxc_request_iomux(MX35_PIN_SD1_CMD, MUX_CONFIG_FUNC);
  189. mxc_request_iomux(MX35_PIN_SD1_CLK, MUX_CONFIG_FUNC);
  190. mxc_request_iomux(MX35_PIN_SD1_DATA0, MUX_CONFIG_FUNC);
  191. mxc_request_iomux(MX35_PIN_SD1_DATA1, MUX_CONFIG_FUNC);
  192. mxc_request_iomux(MX35_PIN_SD1_DATA2, MUX_CONFIG_FUNC);
  193. mxc_request_iomux(MX35_PIN_SD1_DATA3, MUX_CONFIG_FUNC);
  194. /* MMC Card Detect on GPIO1_7 */
  195. mxc_request_iomux(MX35_PIN_SCKT, MUX_CONFIG_ALT5);
  196. mxc_iomux_set_input(MUX_IN_GPIO1_IN_7, 0x1);
  197. gpio_direction_input(GPIO_MMC_CD);
  198. mxc_request_iomux(MX35_PIN_FST, MUX_CONFIG_ALT5);
  199. mxc_iomux_set_input(MUX_IN_GPIO1_IN_8, 0x1);
  200. gpio_direction_output(GPIO_MMC_WP, 0);
  201. esdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
  202. return fsl_esdhc_initialize(bis, &esdhc_cfg);
  203. }
  204. int board_mmc_getcd(struct mmc *mmc)
  205. {
  206. return !gpio_get_value(GPIO_MMC_CD);
  207. }
  208. #endif
  209. u32 get_board_rev(void)
  210. {
  211. int rev = 0;
  212. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  213. }