sdram.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@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 <ppc4xx.h>
  25. #include <asm/processor.h>
  26. #include <asm/io.h>
  27. static void wait_init_complete(void)
  28. {
  29. u32 val;
  30. do {
  31. mfsdram(mem_mcsts, val);
  32. } while (!(val & 0x80000000));
  33. }
  34. /*
  35. * phys_size_t initdram(int board_type)
  36. *
  37. * As the name already indicates, this function is called very early
  38. * from start.S and configures the SDRAM with fixed values. This is needed,
  39. * since the 440EP has no internal SRAM and the 4kB NAND_SPL loader has
  40. * not enough free space to implement the complete I2C SPD DDR autodetection
  41. * routines. Therefore the Bamboo only supports the onboard 64MBytes of SDRAM
  42. * when booting from NAND flash.
  43. *
  44. * Note:
  45. * As found out by Eugene O'Brien <eugene.obrien@advantechamt.com>, the fixed
  46. * DDR setup has problems (U-Boot crashes randomly upon TFTP), when the DIMM
  47. * modules are still plugged in. So it is recommended to remove the DIMM
  48. * modules while using the NAND booting code with the fixed SDRAM setup!
  49. */
  50. phys_size_t initdram(int board_type)
  51. {
  52. /*
  53. * Soft-reset SDRAM controller.
  54. */
  55. mtsdr(sdr_srst, SDR0_SRST_DMC);
  56. mtsdr(sdr_srst, 0x00000000);
  57. /*
  58. * Disable memory controller.
  59. */
  60. mtsdram(mem_cfg0, 0x00000000);
  61. /*
  62. * Setup some default
  63. */
  64. mtsdram(mem_uabba, 0x00000000); /* ubba=0 (default) */
  65. mtsdram(mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
  66. mtsdram(mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
  67. mtsdram(mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
  68. mtsdram(mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
  69. /*
  70. * Following for CAS Latency = 2.5 @ 133 MHz PLB
  71. */
  72. mtsdram(mem_b0cr, 0x00082001);
  73. mtsdram(mem_tr0, 0x41094012);
  74. mtsdram(mem_tr1, 0x8080083d); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/
  75. mtsdram(mem_rtr, 0x04100000); /* Interval 7.8µs @ 133MHz PLB */
  76. mtsdram(mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM*/
  77. /*
  78. * Enable the controller, then wait for DCEN to complete
  79. */
  80. mtsdram(mem_cfg0, 0x80000000); /* DCEN=1, PMUD=0*/
  81. wait_init_complete();
  82. return CONFIG_SYS_MBYTES_SDRAM << 20;
  83. }