idmr.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * (C) Copyright 2000-2006
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/m5271.h>
  25. #include <asm/immap_5271.h>
  26. int checkboard (void) {
  27. puts ("Board: iDMR\n");
  28. return 0;
  29. };
  30. long int initdram (int board_type) {
  31. int i;
  32. /*
  33. * After reset, CS0 is configured to cover entire address space. We
  34. * need to configure it to its proper values, so that writes to
  35. * CFG_SDRAM_BASE and vicinity during SDRAM controller setup below do
  36. * now fall under CS0 (see 16.3.1 of the MCF5271 Reference Manual).
  37. */
  38. /* Flash chipselect, CS0 */
  39. /* ;CSAR0: Flash at 0xFF800000 */
  40. mbar_writeShort(0x0080, 0xFF80);
  41. /* CSCR0: Flash 6 waits, 16bit */
  42. mbar_writeShort(0x008A, 0x1980);
  43. /* CSMR0: Flash 8MB, R/W, valid */
  44. mbar_writeLong(0x0084, 0x007F0001);
  45. /*
  46. * SDRAM configuration proper
  47. */
  48. /*
  49. * Address/Data Pin Assignment Reg.: enable address lines 23-21; do
  50. * not enable data pins D[15:0], as we have 16 bit port to SDRAM
  51. */
  52. mbar_writeByte(MCF_GPIO_PAR_AD,
  53. MCF_GPIO_AD_ADDR23 |
  54. MCF_GPIO_AD_ADDR22 |
  55. MCF_GPIO_AD_ADDR21);
  56. /* No need to configure BS pins - reset values are OK */
  57. /* Chip Select Pin Assignment Reg.: set CS[1-7] to GPIO */
  58. mbar_writeByte(MCF_GPIO_PAR_CS, 0x00);
  59. /* SDRAM Control Pin Assignment Reg. */
  60. mbar_writeByte(MCF_GPIO_PAR_SDRAM,
  61. MCF_GPIO_SDRAM_CSSDCS_00 | /* no matter: PAR_CS=0 */
  62. MCF_GPIO_SDRAM_SDWE |
  63. MCF_GPIO_SDRAM_SCAS |
  64. MCF_GPIO_SDRAM_SRAS |
  65. MCF_GPIO_SDRAM_SCKE |
  66. MCF_GPIO_SDRAM_SDCS_01);
  67. /*
  68. * Wait 100us. We run the bus at 50Mhz, one cycle is 20ns. So 5
  69. * iterations will do, but we do 10 just to be safe.
  70. */
  71. for (i = 0; i < 10; ++i)
  72. asm(" nop");
  73. /* 1. Initialize DRAM Control Register: DCR */
  74. mbar_writeShort(MCF_SDRAMC_DCR,
  75. MCF_SDRAMC_DCR_RTIM(0x10) | /* 65ns */
  76. MCF_SDRAMC_DCR_RC(0x60)); /* 1562 cycles */
  77. /*
  78. * 2. Initialize DACR0
  79. *
  80. * CL: 11 (CL=3: 0x03, 0x02; CL=2: 0x1)
  81. * CBM: cmd at A20, bank select bits 21 and up
  82. * PS: 16 bit
  83. */
  84. mbar_writeLong(MCF_SDRAMC_DACR0,
  85. MCF_SDRAMC_DACRn_BA(CFG_SDRAM_BASE>>18) |
  86. MCF_SDRAMC_DACRn_BA(0x00) |
  87. MCF_SDRAMC_DACRn_CASL(0x03) |
  88. MCF_SDRAMC_DACRn_CBM(0x03) |
  89. MCF_SDRAMC_DACRn_PS(0x03));
  90. /* Initialize DMR0 */
  91. mbar_writeLong(MCF_SDRAMC_DMR0,
  92. MCF_SDRAMC_DMRn_BAM_16M |
  93. MCF_SDRAMC_DMRn_V);
  94. /* 3. Set IP bit in DACR to initiate PALL command */
  95. mbar_writeLong(MCF_SDRAMC_DACR0,
  96. mbar_readLong(MCF_SDRAMC_DACR0) |
  97. MCF_SDRAMC_DACRn_IP);
  98. /* Write to this block to initiate precharge */
  99. *(volatile u16 *)(CFG_SDRAM_BASE) = 0xa5a5;
  100. /*
  101. * Wait at least 20ns to allow banks to precharge (t_RP = 20ns). We
  102. * wait a wee longer, just to be safe.
  103. */
  104. for (i = 0; i < 5; ++i)
  105. asm(" nop");
  106. /* 4. Set RE bit in DACR */
  107. mbar_writeLong(MCF_SDRAMC_DACR0,
  108. mbar_readLong(MCF_SDRAMC_DACR0) |
  109. MCF_SDRAMC_DACRn_RE);
  110. /*
  111. * Wait for at least 8 auto refresh cycles to occur, i.e. at least
  112. * 781 bus cycles.
  113. */
  114. for (i = 0; i < 1000; ++i)
  115. asm(" nop");
  116. /* Finish the configuration by issuing the MRS */
  117. mbar_writeLong(MCF_SDRAMC_DACR0,
  118. mbar_readLong(MCF_SDRAMC_DACR0) |
  119. MCF_SDRAMC_DACRn_MRS);
  120. /*
  121. * Write to the SDRAM Mode Register A0-A11 = 0x400
  122. *
  123. * Write Burst Mode = Programmed Burst Length
  124. * Op Mode = Standard Op
  125. * CAS Latency = 3
  126. * Burst Type = Sequential
  127. * Burst Length = 1
  128. */
  129. *(volatile u32 *)(CFG_SDRAM_BASE + 0x1800) = 0xa5a5a5a5;
  130. return CFG_SDRAM_SIZE * 1024 * 1024;
  131. };
  132. int testdram (void) {
  133. /* TODO: XXX XXX XXX */
  134. printf ("DRAM test not implemented!\n");
  135. return (0);
  136. }