flea3.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
  3. *
  4. * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
  5. *
  6. * Copyright (C) 2011, Stefano Babic <sbabic@denx.de>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/io.h>
  28. #include <asm/errno.h>
  29. #include <asm/arch/imx-regs.h>
  30. #include <asm/arch/crm_regs.h>
  31. #include <asm/arch/mx35_pins.h>
  32. #include <asm/arch/iomux.h>
  33. #include <i2c.h>
  34. #include <linux/types.h>
  35. #include <asm/gpio.h>
  36. #include <asm/arch/sys_proto.h>
  37. #include <netdev.h>
  38. #ifndef CONFIG_BOARD_EARLY_INIT_F
  39. #error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
  40. #endif
  41. #define CCM_CCMR_CONFIG 0x003F4208
  42. #define ESDCTL_DDR2_CONFIG 0x007FFC3F
  43. #define ESDCTL_0x92220000 0x92220000
  44. #define ESDCTL_0xA2220000 0xA2220000
  45. #define ESDCTL_0xB2220000 0xB2220000
  46. #define ESDCTL_0x82228080 0x82228080
  47. #define ESDCTL_DDR2_EMR2 0x04000000
  48. #define ESDCTL_DDR2_EMR3 0x06000000
  49. #define ESDCTL_PRECHARGE 0x00000400
  50. #define ESDCTL_DDR2_EN_DLL 0x02000400
  51. #define ESDCTL_DDR2_RESET_DLL 0x00000333
  52. #define ESDCTL_DDR2_MR 0x00000233
  53. #define ESDCTL_DDR2_OCD_DEFAULT 0x02000780
  54. #define ESDCTL_DELAY_LINE5 0x00F49F00
  55. static inline void dram_wait(unsigned int count)
  56. {
  57. volatile unsigned int wait = count;
  58. while (wait--)
  59. ;
  60. }
  61. DECLARE_GLOBAL_DATA_PTR;
  62. int dram_init(void)
  63. {
  64. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
  65. PHYS_SDRAM_1_SIZE);
  66. return 0;
  67. }
  68. static void board_setup_sdram_bank(u32 start_address)
  69. {
  70. struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
  71. u32 *cfg_reg, *ctl_reg;
  72. u32 val;
  73. switch (start_address) {
  74. case CSD0_BASE_ADDR:
  75. cfg_reg = &esdc->esdcfg0;
  76. ctl_reg = &esdc->esdctl0;
  77. break;
  78. case CSD1_BASE_ADDR:
  79. cfg_reg = &esdc->esdcfg1;
  80. ctl_reg = &esdc->esdctl1;
  81. break;
  82. default:
  83. return;
  84. }
  85. /* Initialize MISC register for DDR2 */
  86. val = ESDC_MISC_RST | ESDC_MISC_MDDR_EN | ESDC_MISC_MDDR_DL_RST |
  87. ESDC_MISC_DDR_EN | ESDC_MISC_DDR2_EN;
  88. writel(val, &esdc->esdmisc);
  89. val &= ~(ESDC_MISC_RST | ESDC_MISC_MDDR_DL_RST);
  90. writel(val, &esdc->esdmisc);
  91. /*
  92. * according to DDR2 specs, wait a while before
  93. * the PRECHARGE_ALL command
  94. */
  95. dram_wait(0x20000);
  96. /* Load DDR2 config and timing */
  97. writel(ESDCTL_DDR2_CONFIG, cfg_reg);
  98. /* Precharge ALL */
  99. writel(ESDCTL_0x92220000,
  100. ctl_reg);
  101. writel(0xda, start_address + ESDCTL_PRECHARGE);
  102. /* Load mode */
  103. writel(ESDCTL_0xB2220000,
  104. ctl_reg);
  105. writeb(0xda, start_address + ESDCTL_DDR2_EMR2); /* EMRS2 */
  106. writeb(0xda, start_address + ESDCTL_DDR2_EMR3); /* EMRS3 */
  107. writeb(0xda, start_address + ESDCTL_DDR2_EN_DLL); /* Enable DLL */
  108. writeb(0xda, start_address + ESDCTL_DDR2_RESET_DLL); /* Reset DLL */
  109. /* Precharge ALL */
  110. writel(ESDCTL_0x92220000,
  111. ctl_reg);
  112. writel(0xda, start_address + ESDCTL_PRECHARGE);
  113. /* Set mode auto refresh : at least two refresh are required */
  114. writel(ESDCTL_0xA2220000,
  115. ctl_reg);
  116. writel(0xda, start_address);
  117. writel(0xda, start_address);
  118. writel(ESDCTL_0xB2220000,
  119. ctl_reg);
  120. writeb(0xda, start_address + ESDCTL_DDR2_MR);
  121. writeb(0xda, start_address + ESDCTL_DDR2_OCD_DEFAULT);
  122. /* OCD mode exit */
  123. writeb(0xda, start_address + ESDCTL_DDR2_EN_DLL); /* Enable DLL */
  124. /* Set normal mode */
  125. writel(ESDCTL_0x82228080,
  126. ctl_reg);
  127. dram_wait(0x20000);
  128. /* Do not set delay lines, only for MDDR */
  129. }
  130. static void board_setup_sdram(void)
  131. {
  132. struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
  133. /* Initialize with default values both CSD0/1 */
  134. writel(0x2000, &esdc->esdctl0);
  135. writel(0x2000, &esdc->esdctl1);
  136. board_setup_sdram_bank(CSD0_BASE_ADDR);
  137. }
  138. static void setup_iomux_uart3(void)
  139. {
  140. mxc_request_iomux(MX35_PIN_RTS2_UART3_RXD_MUX, MUX_CONFIG_ALT7);
  141. mxc_request_iomux(MX35_PIN_CTS2_UART3_TXD_MUX, MUX_CONFIG_ALT7);
  142. }
  143. static void setup_iomux_i2c(void)
  144. {
  145. int pad;
  146. mxc_request_iomux(MX35_PIN_I2C1_CLK, MUX_CONFIG_SION);
  147. mxc_request_iomux(MX35_PIN_I2C1_DAT, MUX_CONFIG_SION);
  148. pad = (PAD_CTL_HYS_SCHMITZ | PAD_CTL_PKE_ENABLE \
  149. | PAD_CTL_PUE_PUD | PAD_CTL_ODE_OpenDrain);
  150. mxc_iomux_set_pad(MX35_PIN_I2C1_CLK, pad);
  151. mxc_iomux_set_pad(MX35_PIN_I2C1_DAT, pad);
  152. mxc_request_iomux(MX35_PIN_TX3_RX2, MUX_CONFIG_ALT1);
  153. mxc_request_iomux(MX35_PIN_TX2_RX3, MUX_CONFIG_ALT1);
  154. mxc_iomux_set_pad(MX35_PIN_TX3_RX2, pad);
  155. mxc_iomux_set_pad(MX35_PIN_TX2_RX3, pad);
  156. }
  157. static void setup_iomux_spi(void)
  158. {
  159. mxc_request_iomux(MX35_PIN_CSPI1_MOSI, MUX_CONFIG_SION);
  160. mxc_request_iomux(MX35_PIN_CSPI1_MISO, MUX_CONFIG_SION);
  161. mxc_request_iomux(MX35_PIN_CSPI1_SS0, MUX_CONFIG_SION);
  162. mxc_request_iomux(MX35_PIN_CSPI1_SS1, MUX_CONFIG_SION);
  163. mxc_request_iomux(MX35_PIN_CSPI1_SCLK, MUX_CONFIG_SION);
  164. }
  165. static void setup_iomux_fec(void)
  166. {
  167. /* setup pins for FEC */
  168. mxc_request_iomux(MX35_PIN_FEC_TX_CLK, MUX_CONFIG_FUNC);
  169. mxc_request_iomux(MX35_PIN_FEC_RX_CLK, MUX_CONFIG_FUNC);
  170. mxc_request_iomux(MX35_PIN_FEC_RX_DV, MUX_CONFIG_FUNC);
  171. mxc_request_iomux(MX35_PIN_FEC_COL, MUX_CONFIG_FUNC);
  172. mxc_request_iomux(MX35_PIN_FEC_RDATA0, MUX_CONFIG_FUNC);
  173. mxc_request_iomux(MX35_PIN_FEC_TDATA0, MUX_CONFIG_FUNC);
  174. mxc_request_iomux(MX35_PIN_FEC_TX_EN, MUX_CONFIG_FUNC);
  175. mxc_request_iomux(MX35_PIN_FEC_MDC, MUX_CONFIG_FUNC);
  176. mxc_request_iomux(MX35_PIN_FEC_MDIO, MUX_CONFIG_FUNC);
  177. mxc_request_iomux(MX35_PIN_FEC_TX_ERR, MUX_CONFIG_FUNC);
  178. mxc_request_iomux(MX35_PIN_FEC_RX_ERR, MUX_CONFIG_FUNC);
  179. mxc_request_iomux(MX35_PIN_FEC_CRS, MUX_CONFIG_FUNC);
  180. mxc_request_iomux(MX35_PIN_FEC_RDATA1, MUX_CONFIG_FUNC);
  181. mxc_request_iomux(MX35_PIN_FEC_TDATA1, MUX_CONFIG_FUNC);
  182. mxc_request_iomux(MX35_PIN_FEC_RDATA2, MUX_CONFIG_FUNC);
  183. mxc_request_iomux(MX35_PIN_FEC_TDATA2, MUX_CONFIG_FUNC);
  184. mxc_request_iomux(MX35_PIN_FEC_RDATA3, MUX_CONFIG_FUNC);
  185. mxc_request_iomux(MX35_PIN_FEC_TDATA3, MUX_CONFIG_FUNC);
  186. }
  187. int board_early_init_f(void)
  188. {
  189. struct ccm_regs *ccm =
  190. (struct ccm_regs *)IMX_CCM_BASE;
  191. /* setup GPIO3_1 to set HighVCore signal */
  192. mxc_request_iomux(MX35_PIN_ATA_DA1, MUX_CONFIG_ALT5);
  193. gpio_direction_output(65, 1);
  194. /* initialize PLL and clock configuration */
  195. writel(CCM_CCMR_CONFIG, &ccm->ccmr);
  196. writel(CCM_MPLL_532_HZ, &ccm->mpctl);
  197. writel(CCM_PPLL_300_HZ, &ccm->ppctl);
  198. /* Set the core to run at 532 Mhz */
  199. writel(0x00001000, &ccm->pdr0);
  200. /* Set-up RAM */
  201. board_setup_sdram();
  202. /* enable clocks */
  203. writel(readl(&ccm->cgr0) |
  204. MXC_CCM_CGR0_EMI_MASK |
  205. MXC_CCM_CGR0_EDI0_MASK |
  206. MXC_CCM_CGR0_EPIT1_MASK,
  207. &ccm->cgr0);
  208. writel(readl(&ccm->cgr1) |
  209. MXC_CCM_CGR1_FEC_MASK |
  210. MXC_CCM_CGR1_GPIO1_MASK |
  211. MXC_CCM_CGR1_GPIO2_MASK |
  212. MXC_CCM_CGR1_GPIO3_MASK |
  213. MXC_CCM_CGR1_I2C1_MASK |
  214. MXC_CCM_CGR1_I2C2_MASK |
  215. MXC_CCM_CGR1_I2C3_MASK,
  216. &ccm->cgr1);
  217. /* Set-up NAND */
  218. __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
  219. /* Set pinmux for the required peripherals */
  220. setup_iomux_uart3();
  221. setup_iomux_i2c();
  222. setup_iomux_fec();
  223. setup_iomux_spi();
  224. return 0;
  225. }
  226. int board_init(void)
  227. {
  228. /* address of boot parameters */
  229. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  230. return 0;
  231. }
  232. u32 get_board_rev(void)
  233. {
  234. int rev = 0;
  235. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  236. }