idmr.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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/immap.h>
  25. int checkboard (void) {
  26. puts ("Board: iDMR\n");
  27. return 0;
  28. };
  29. long int initdram (int board_type) {
  30. int i;
  31. /*
  32. * After reset, CS0 is configured to cover entire address space. We
  33. * need to configure it to its proper values, so that writes to
  34. * CFG_SDRAM_BASE and vicinity during SDRAM controller setup below do
  35. * now fall under CS0 (see 16.3.1 of the MCF5271 Reference Manual).
  36. */
  37. /* Flash chipselect, CS0 */
  38. /* ;CSAR0: Flash at 0xFF800000 */
  39. mbar_writeShort(0x0080, 0xFF80);
  40. /* CSCR0: Flash 6 waits, 16bit */
  41. mbar_writeShort(0x008A, 0x1980);
  42. /* CSMR0: Flash 8MB, R/W, valid */
  43. mbar_writeLong(0x0084, 0x007F0001);
  44. /*
  45. * SDRAM configuration proper
  46. */
  47. /*
  48. * Address/Data Pin Assignment Reg.: enable address lines 23-21; do
  49. * not enable data pins D[15:0], as we have 16 bit port to SDRAM
  50. */
  51. mbar_writeByte(MCF_GPIO_PAR_AD,
  52. MCF_GPIO_AD_ADDR23 |
  53. MCF_GPIO_AD_ADDR22 |
  54. MCF_GPIO_AD_ADDR21);
  55. /* No need to configure BS pins - reset values are OK */
  56. /* Chip Select Pin Assignment Reg.: set CS[1-7] to GPIO */
  57. mbar_writeByte(MCF_GPIO_PAR_CS, 0x00);
  58. /* SDRAM Control Pin Assignment Reg. */
  59. mbar_writeByte(MCF_GPIO_PAR_SDRAM,
  60. MCF_GPIO_SDRAM_CSSDCS_00 | /* no matter: PAR_CS=0 */
  61. MCF_GPIO_SDRAM_SDWE |
  62. MCF_GPIO_SDRAM_SCAS |
  63. MCF_GPIO_SDRAM_SRAS |
  64. MCF_GPIO_SDRAM_SCKE |
  65. MCF_GPIO_SDRAM_SDCS_01);
  66. /*
  67. * Wait 100us. We run the bus at 50Mhz, one cycle is 20ns. So 5
  68. * iterations will do, but we do 10 just to be safe.
  69. */
  70. for (i = 0; i < 10; ++i)
  71. asm(" nop");
  72. /* 1. Initialize DRAM Control Register: DCR */
  73. mbar_writeShort(MCF_SDRAMC_DCR,
  74. MCF_SDRAMC_DCR_RTIM(0x10) | /* 65ns */
  75. MCF_SDRAMC_DCR_RC(0x60)); /* 1562 cycles */
  76. /*
  77. * 2. Initialize DACR0
  78. *
  79. * CL: 11 (CL=3: 0x03, 0x02; CL=2: 0x1)
  80. * CBM: cmd at A20, bank select bits 21 and up
  81. * PS: 16 bit
  82. */
  83. mbar_writeLong(MCF_SDRAMC_DACR0,
  84. MCF_SDRAMC_DACRn_BA(CFG_SDRAM_BASE>>18) |
  85. MCF_SDRAMC_DACRn_BA(0x00) |
  86. MCF_SDRAMC_DACRn_CASL(0x03) |
  87. MCF_SDRAMC_DACRn_CBM(0x03) |
  88. MCF_SDRAMC_DACRn_PS(0x03));
  89. /* Initialize DMR0 */
  90. mbar_writeLong(MCF_SDRAMC_DMR0,
  91. MCF_SDRAMC_DMRn_BAM_16M |
  92. MCF_SDRAMC_DMRn_V);
  93. /* 3. Set IP bit in DACR to initiate PALL command */
  94. mbar_writeLong(MCF_SDRAMC_DACR0,
  95. mbar_readLong(MCF_SDRAMC_DACR0) |
  96. MCF_SDRAMC_DACRn_IP);
  97. /* Write to this block to initiate precharge */
  98. *(volatile u16 *)(CFG_SDRAM_BASE) = 0xa5a5;
  99. /*
  100. * Wait at least 20ns to allow banks to precharge (t_RP = 20ns). We
  101. * wait a wee longer, just to be safe.
  102. */
  103. for (i = 0; i < 5; ++i)
  104. asm(" nop");
  105. /* 4. Set RE bit in DACR */
  106. mbar_writeLong(MCF_SDRAMC_DACR0,
  107. mbar_readLong(MCF_SDRAMC_DACR0) |
  108. MCF_SDRAMC_DACRn_RE);
  109. /*
  110. * Wait for at least 8 auto refresh cycles to occur, i.e. at least
  111. * 781 bus cycles.
  112. */
  113. for (i = 0; i < 1000; ++i)
  114. asm(" nop");
  115. /* Finish the configuration by issuing the MRS */
  116. mbar_writeLong(MCF_SDRAMC_DACR0,
  117. mbar_readLong(MCF_SDRAMC_DACR0) |
  118. MCF_SDRAMC_DACRn_MRS);
  119. /*
  120. * Write to the SDRAM Mode Register A0-A11 = 0x400
  121. *
  122. * Write Burst Mode = Programmed Burst Length
  123. * Op Mode = Standard Op
  124. * CAS Latency = 3
  125. * Burst Type = Sequential
  126. * Burst Length = 1
  127. */
  128. *(volatile u32 *)(CFG_SDRAM_BASE + 0x1800) = 0xa5a5a5a5;
  129. return CFG_SDRAM_SIZE * 1024 * 1024;
  130. };
  131. int testdram (void) {
  132. /* TODO: XXX XXX XXX */
  133. printf ("DRAM test not implemented!\n");
  134. return (0);
  135. }