dram.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * (C) Copyright 2011
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Lei Wen <leiwen@marvell.com>,
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #include <common.h>
  25. #include <asm/arch/pantheon.h>
  26. DECLARE_GLOBAL_DATA_PTR;
  27. /*
  28. * Pantheon DRAM controller supports upto 8 banks
  29. * for chip select 0 and 1
  30. */
  31. /*
  32. * DDR Memory Control Registers
  33. * Refer Datasheet 4.4
  34. */
  35. struct panthddr_map_registers {
  36. u32 cs; /* Memory Address Map Register -CS */
  37. u32 pad[3];
  38. };
  39. struct panthddr_registers {
  40. u8 pad[0x100 - 0x000];
  41. struct panthddr_map_registers mmap[2];
  42. };
  43. /*
  44. * panth_sdram_base - reads SDRAM Base Address Register
  45. */
  46. u32 panth_sdram_base(int chip_sel)
  47. {
  48. struct panthddr_registers *ddr_regs =
  49. (struct panthddr_registers *)PANTHEON_DRAM_BASE;
  50. u32 result = 0;
  51. u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
  52. if (!CS_valid)
  53. return 0;
  54. result = readl(&ddr_regs->mmap[chip_sel].cs) & 0xFF800000;
  55. return result;
  56. }
  57. /*
  58. * panth_sdram_size - reads SDRAM size
  59. */
  60. u32 panth_sdram_size(int chip_sel)
  61. {
  62. struct panthddr_registers *ddr_regs =
  63. (struct panthddr_registers *)PANTHEON_DRAM_BASE;
  64. u32 result = 0;
  65. u32 CS_valid = 0x01 & readl(&ddr_regs->mmap[chip_sel].cs);
  66. if (!CS_valid)
  67. return 0;
  68. result = readl(&ddr_regs->mmap[chip_sel].cs);
  69. result = (result >> 16) & 0xF;
  70. if (result < 0x7) {
  71. printf("Unknown DRAM Size\n");
  72. return -1;
  73. } else {
  74. return ((0x8 << (result - 0x7)) * 1024 * 1024);
  75. }
  76. }
  77. #ifndef CONFIG_SYS_BOARD_DRAM_INIT
  78. int dram_init(void)
  79. {
  80. int i;
  81. gd->ram_size = 0;
  82. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  83. gd->bd->bi_dram[i].start = panth_sdram_base(i);
  84. gd->bd->bi_dram[i].size = panth_sdram_size(i);
  85. /*
  86. * It is assumed that all memory banks are consecutive
  87. * and without gaps.
  88. * If the gap is found, ram_size will be reported for
  89. * consecutive memory only
  90. */
  91. if (gd->bd->bi_dram[i].start != gd->ram_size)
  92. break;
  93. gd->ram_size += gd->bd->bi_dram[i].size;
  94. }
  95. for (; i < CONFIG_NR_DRAM_BANKS; i++) {
  96. /*
  97. * If above loop terminated prematurely, we need to set
  98. * remaining banks' start address & size as 0. Otherwise other
  99. * u-boot functions and Linux kernel gets wrong values which
  100. * could result in crash
  101. */
  102. gd->bd->bi_dram[i].start = 0;
  103. gd->bd->bi_dram[i].size = 0;
  104. }
  105. return 0;
  106. }
  107. /*
  108. * If this function is not defined here,
  109. * board.c alters dram bank zero configuration defined above.
  110. */
  111. void dram_init_banksize(void)
  112. {
  113. dram_init();
  114. }
  115. #endif /* CONFIG_SYS_BOARD_DRAM_INIT */