flea3.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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/iomux-mx35.h>
  32. #include <i2c.h>
  33. #include <linux/types.h>
  34. #include <asm/gpio.h>
  35. #include <asm/arch/sys_proto.h>
  36. #include <netdev.h>
  37. #ifndef CONFIG_BOARD_EARLY_INIT_F
  38. #error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
  39. #endif
  40. #define CCM_CCMR_CONFIG 0x003F4208
  41. #define ESDCTL_DDR2_CONFIG 0x007FFC3F
  42. #define ESDCTL_0x92220000 0x92220000
  43. #define ESDCTL_0xA2220000 0xA2220000
  44. #define ESDCTL_0xB2220000 0xB2220000
  45. #define ESDCTL_0x82228080 0x82228080
  46. #define ESDCTL_DDR2_EMR2 0x04000000
  47. #define ESDCTL_DDR2_EMR3 0x06000000
  48. #define ESDCTL_PRECHARGE 0x00000400
  49. #define ESDCTL_DDR2_EN_DLL 0x02000400
  50. #define ESDCTL_DDR2_RESET_DLL 0x00000333
  51. #define ESDCTL_DDR2_MR 0x00000233
  52. #define ESDCTL_DDR2_OCD_DEFAULT 0x02000780
  53. #define ESDCTL_DELAY_LINE5 0x00F49F00
  54. static inline void dram_wait(unsigned int count)
  55. {
  56. volatile unsigned int wait = count;
  57. while (wait--)
  58. ;
  59. }
  60. DECLARE_GLOBAL_DATA_PTR;
  61. int dram_init(void)
  62. {
  63. gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
  64. PHYS_SDRAM_1_SIZE);
  65. return 0;
  66. }
  67. static void board_setup_sdram_bank(u32 start_address)
  68. {
  69. struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
  70. u32 *cfg_reg, *ctl_reg;
  71. u32 val;
  72. switch (start_address) {
  73. case CSD0_BASE_ADDR:
  74. cfg_reg = &esdc->esdcfg0;
  75. ctl_reg = &esdc->esdctl0;
  76. break;
  77. case CSD1_BASE_ADDR:
  78. cfg_reg = &esdc->esdcfg1;
  79. ctl_reg = &esdc->esdctl1;
  80. break;
  81. default:
  82. return;
  83. }
  84. /* Initialize MISC register for DDR2 */
  85. val = ESDC_MISC_RST | ESDC_MISC_MDDR_EN | ESDC_MISC_MDDR_DL_RST |
  86. ESDC_MISC_DDR_EN | ESDC_MISC_DDR2_EN;
  87. writel(val, &esdc->esdmisc);
  88. val &= ~(ESDC_MISC_RST | ESDC_MISC_MDDR_DL_RST);
  89. writel(val, &esdc->esdmisc);
  90. /*
  91. * according to DDR2 specs, wait a while before
  92. * the PRECHARGE_ALL command
  93. */
  94. dram_wait(0x20000);
  95. /* Load DDR2 config and timing */
  96. writel(ESDCTL_DDR2_CONFIG, cfg_reg);
  97. /* Precharge ALL */
  98. writel(ESDCTL_0x92220000,
  99. ctl_reg);
  100. writel(0xda, start_address + ESDCTL_PRECHARGE);
  101. /* Load mode */
  102. writel(ESDCTL_0xB2220000,
  103. ctl_reg);
  104. writeb(0xda, start_address + ESDCTL_DDR2_EMR2); /* EMRS2 */
  105. writeb(0xda, start_address + ESDCTL_DDR2_EMR3); /* EMRS3 */
  106. writeb(0xda, start_address + ESDCTL_DDR2_EN_DLL); /* Enable DLL */
  107. writeb(0xda, start_address + ESDCTL_DDR2_RESET_DLL); /* Reset DLL */
  108. /* Precharge ALL */
  109. writel(ESDCTL_0x92220000,
  110. ctl_reg);
  111. writel(0xda, start_address + ESDCTL_PRECHARGE);
  112. /* Set mode auto refresh : at least two refresh are required */
  113. writel(ESDCTL_0xA2220000,
  114. ctl_reg);
  115. writel(0xda, start_address);
  116. writel(0xda, start_address);
  117. writel(ESDCTL_0xB2220000,
  118. ctl_reg);
  119. writeb(0xda, start_address + ESDCTL_DDR2_MR);
  120. writeb(0xda, start_address + ESDCTL_DDR2_OCD_DEFAULT);
  121. /* OCD mode exit */
  122. writeb(0xda, start_address + ESDCTL_DDR2_EN_DLL); /* Enable DLL */
  123. /* Set normal mode */
  124. writel(ESDCTL_0x82228080,
  125. ctl_reg);
  126. dram_wait(0x20000);
  127. /* Do not set delay lines, only for MDDR */
  128. }
  129. static void board_setup_sdram(void)
  130. {
  131. struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
  132. /* Initialize with default values both CSD0/1 */
  133. writel(0x2000, &esdc->esdctl0);
  134. writel(0x2000, &esdc->esdctl1);
  135. board_setup_sdram_bank(CSD0_BASE_ADDR);
  136. }
  137. static void setup_iomux_uart3(void)
  138. {
  139. static const iomux_v3_cfg_t uart3_pads[] = {
  140. MX35_PAD_RTS2__UART3_RXD_MUX,
  141. MX35_PAD_CTS2__UART3_TXD_MUX,
  142. };
  143. imx_iomux_v3_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
  144. }
  145. #define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_ODE)
  146. static void setup_iomux_i2c(void)
  147. {
  148. static const iomux_v3_cfg_t i2c_pads[] = {
  149. NEW_PAD_CTRL(MX35_PAD_I2C1_CLK__I2C1_SCL, I2C_PAD_CTRL),
  150. NEW_PAD_CTRL(MX35_PAD_I2C1_DAT__I2C1_SDA, I2C_PAD_CTRL),
  151. NEW_PAD_CTRL(MX35_PAD_TX3_RX2__I2C3_SCL, I2C_PAD_CTRL),
  152. NEW_PAD_CTRL(MX35_PAD_TX2_RX3__I2C3_SDA, I2C_PAD_CTRL),
  153. };
  154. imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads));
  155. }
  156. static void setup_iomux_spi(void)
  157. {
  158. static const iomux_v3_cfg_t spi_pads[] = {
  159. MX35_PAD_CSPI1_MOSI__CSPI1_MOSI,
  160. MX35_PAD_CSPI1_MISO__CSPI1_MISO,
  161. MX35_PAD_CSPI1_SS0__CSPI1_SS0,
  162. MX35_PAD_CSPI1_SS1__CSPI1_SS1,
  163. MX35_PAD_CSPI1_SCLK__CSPI1_SCLK,
  164. };
  165. imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
  166. }
  167. static void setup_iomux_fec(void)
  168. {
  169. static const iomux_v3_cfg_t fec_pads[] = {
  170. MX35_PAD_FEC_TX_CLK__FEC_TX_CLK,
  171. MX35_PAD_FEC_RX_CLK__FEC_RX_CLK,
  172. MX35_PAD_FEC_RX_DV__FEC_RX_DV,
  173. MX35_PAD_FEC_COL__FEC_COL,
  174. MX35_PAD_FEC_RDATA0__FEC_RDATA_0,
  175. MX35_PAD_FEC_TDATA0__FEC_TDATA_0,
  176. MX35_PAD_FEC_TX_EN__FEC_TX_EN,
  177. MX35_PAD_FEC_MDC__FEC_MDC,
  178. MX35_PAD_FEC_MDIO__FEC_MDIO,
  179. MX35_PAD_FEC_TX_ERR__FEC_TX_ERR,
  180. MX35_PAD_FEC_RX_ERR__FEC_RX_ERR,
  181. MX35_PAD_FEC_CRS__FEC_CRS,
  182. MX35_PAD_FEC_RDATA1__FEC_RDATA_1,
  183. MX35_PAD_FEC_TDATA1__FEC_TDATA_1,
  184. MX35_PAD_FEC_RDATA2__FEC_RDATA_2,
  185. MX35_PAD_FEC_TDATA2__FEC_TDATA_2,
  186. MX35_PAD_FEC_RDATA3__FEC_RDATA_3,
  187. MX35_PAD_FEC_TDATA3__FEC_TDATA_3,
  188. };
  189. /* setup pins for FEC */
  190. imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
  191. }
  192. int board_early_init_f(void)
  193. {
  194. struct ccm_regs *ccm =
  195. (struct ccm_regs *)IMX_CCM_BASE;
  196. /* setup GPIO3_1 to set HighVCore signal */
  197. imx_iomux_v3_setup_pad(MX35_PAD_ATA_DA1__GPIO3_1);
  198. gpio_direction_output(65, 1);
  199. /* initialize PLL and clock configuration */
  200. writel(CCM_CCMR_CONFIG, &ccm->ccmr);
  201. writel(CCM_MPLL_532_HZ, &ccm->mpctl);
  202. writel(CCM_PPLL_300_HZ, &ccm->ppctl);
  203. /* Set the core to run at 532 Mhz */
  204. writel(0x00001000, &ccm->pdr0);
  205. /* Set-up RAM */
  206. board_setup_sdram();
  207. /* enable clocks */
  208. writel(readl(&ccm->cgr0) |
  209. MXC_CCM_CGR0_EMI_MASK |
  210. MXC_CCM_CGR0_EDIO_MASK |
  211. MXC_CCM_CGR0_EPIT1_MASK,
  212. &ccm->cgr0);
  213. writel(readl(&ccm->cgr1) |
  214. MXC_CCM_CGR1_FEC_MASK |
  215. MXC_CCM_CGR1_GPIO1_MASK |
  216. MXC_CCM_CGR1_GPIO2_MASK |
  217. MXC_CCM_CGR1_GPIO3_MASK |
  218. MXC_CCM_CGR1_I2C1_MASK |
  219. MXC_CCM_CGR1_I2C2_MASK |
  220. MXC_CCM_CGR1_I2C3_MASK,
  221. &ccm->cgr1);
  222. /* Set-up NAND */
  223. __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
  224. /* Set pinmux for the required peripherals */
  225. setup_iomux_uart3();
  226. setup_iomux_i2c();
  227. setup_iomux_fec();
  228. setup_iomux_spi();
  229. return 0;
  230. }
  231. int board_init(void)
  232. {
  233. /* address of boot parameters */
  234. gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
  235. return 0;
  236. }
  237. u32 get_board_rev(void)
  238. {
  239. int rev = 0;
  240. return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
  241. }