m5235evb.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  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 <config.h>
  27. #include <common.h>
  28. #include <asm/immap.h>
  29. #include <asm/io.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. int checkboard(void)
  32. {
  33. puts("Board: ");
  34. puts("Freescale M5235 EVB\n");
  35. return 0;
  36. };
  37. phys_size_t initdram(int board_type)
  38. {
  39. sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
  40. gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
  41. u32 dramsize, i, dramclk;
  42. /*
  43. * When booting from external Flash, the port-size is less than
  44. * the port-size of SDRAM. In this case it is necessary to enable
  45. * Data[15:0] on Port Address/Data.
  46. */
  47. out_8(&gpio->par_ad,
  48. GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 |
  49. GPIO_PAR_AD_DATAL);
  50. /* Initialize PAR to enable SDRAM signals */
  51. out_8(&gpio->par_sdram,
  52. GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS |
  53. GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE |
  54. GPIO_PAR_SDRAM_SDCS(3));
  55. dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
  56. for (i = 0x13; i < 0x20; i++) {
  57. if (dramsize == (1 << i))
  58. break;
  59. }
  60. i--;
  61. if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) {
  62. dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
  63. /* Initialize DRAM Control Register: DCR */
  64. out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS |
  65. SDRAMC_DCR_RTIM_6CLKS |
  66. SDRAMC_DCR_RC((15 * dramclk) >> 4));
  67. /* Initialize DACR0 */
  68. out_be32(&sdram->dacr0,
  69. SDRAMC_DARCn_BA(CONFIG_SYS_SDRAM_BASE) |
  70. SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 |
  71. SDRAMC_DARCn_PS_32);
  72. asm("nop");
  73. /* Initialize DMR0 */
  74. out_be32(&sdram->dmr0,
  75. ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V);
  76. asm("nop");
  77. /* Set IP (bit 3) in DACR */
  78. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP);
  79. /* Wait 30ns to allow banks to precharge */
  80. for (i = 0; i < 5; i++) {
  81. asm("nop");
  82. }
  83. /* Write to this block to initiate precharge */
  84. *(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
  85. /* Set RE (bit 15) in DACR */
  86. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE);
  87. /* Wait for at least 8 auto refresh cycles to occur */
  88. for (i = 0; i < 0x2000; i++) {
  89. asm("nop");
  90. }
  91. /* Finish the configuration by issuing the MRS. */
  92. setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS);
  93. asm("nop");
  94. /* Write to the SDRAM Mode Register */
  95. *(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
  96. }
  97. return dramsize;
  98. };
  99. int testdram(void)
  100. {
  101. /* TODO: XXX XXX XXX */
  102. printf("DRAM test not implemented!\n");
  103. return (0);
  104. }