sdram.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * (C) Copyright 2002-2004
  3. * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
  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. #ifdef CONFIG_SDRAM_BANK0
  27. #define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data)
  28. struct sdram_conf_s {
  29. unsigned long size;
  30. unsigned long reg;
  31. };
  32. typedef struct sdram_conf_s sdram_conf_t;
  33. sdram_conf_t mb0cf[] = {
  34. {(128 << 20), 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */
  35. {(64 << 20), 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */
  36. {(32 << 20), 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */
  37. {(16 << 20), 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */
  38. {(4 << 20), 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */
  39. };
  40. #define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0]))
  41. void sdram_init(void)
  42. {
  43. ulong sdtr1;
  44. ulong rtr;
  45. int i;
  46. /*
  47. * Support for 100MHz and 133MHz SDRAM
  48. */
  49. if (get_bus_freq(0) > 100000000) {
  50. /*
  51. * 133 MHz SDRAM
  52. */
  53. sdtr1 = 0x01074015;
  54. rtr = 0x07f00000;
  55. } else {
  56. /*
  57. * default: 100 MHz SDRAM
  58. */
  59. sdtr1 = 0x0086400d;
  60. rtr = 0x05f00000;
  61. }
  62. for (i=0; i<N_MB0CF; i++) {
  63. /*
  64. * Disable memory controller.
  65. */
  66. mtsdram0(mem_mcopt1, 0x00000000);
  67. /*
  68. * Set MB0CF for bank 0.
  69. */
  70. mtsdram0(mem_mb0cf, mb0cf[i].reg);
  71. mtsdram0(mem_sdtr1, sdtr1);
  72. mtsdram0(mem_rtr, rtr);
  73. udelay(200);
  74. /*
  75. * Set memory controller options reg, MCOPT1.
  76. * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
  77. * read/prefetch.
  78. */
  79. mtsdram0(mem_mcopt1, 0x80800000);
  80. udelay(10000);
  81. if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) {
  82. /*
  83. * OK, size detected -> all done
  84. */
  85. return;
  86. }
  87. }
  88. }
  89. #endif /* CONFIG_SDRAM_BANK0 */